package tankgame03;

public class Shot implements Runnable{
    int x;
    int y;
    int direct=0;
    int speed=3;
    boolean isLive=true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {//射击行为
        while (true){
            //子弹休眠
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            switch (direct){
                case 0://向上
                    y-=speed;
                    break;
                case 1://向右
                    x+=speed;
                    break;
                case 2://向左
                    x-=speed;
                    break;
                case 3://向下
                    y+=speed;
                    break;
            }
            //测试
            System.out.println("x"+x+"y"+y);
            //碰到边界就退出
            if (!(x>=0&&x<=1000&&y>=0&&y<=750)){
                isLive=false;
                break;
            }
        }

    }
}
